package com.xiaotu.Mapper;

import com.xiaotu.pojo.Discuss;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface DiscussRepository extends JpaRepository<Discuss,Integer> {
    //1.查询author非空的DIscuss评论集合
    public List<Discuss> findByAuthorNotNull();
    //2.根据文章id分页查询Discuss评论集合
    @Query("select c from t_comment c where c.aId=?1")
    public List<Discuss> getDiscussPaged(Integer aid, Pageable pageable);
    //3.使用袁术SQL语句 根据文章id分页查询Discuss评论集合
    @Query(value = "select * from t_comment where a_id =?1",nativeQuery = true)
    public List<Discuss> getDiscussPaged2(Integer aid,Pageable pageable);
    //4.根据评论id修改评论作者 author
    @Transactional
    @Modifying
    @Query("update t_comment c set c.author=?1 where c.id =?1")
    public Integer updateDiscuss(String author,Integer id);
    @Transactional
    @Modifying
    @Query("delete t_comment c where c.id=?1")
    public int deleteDiscuss(Integer id);

}
